# -*- coding: utf-8 -*-
import scrapy
from DemoTianQi.items import DemotianqiItem

class TianqispiderSpider(scrapy.Spider):
	name = 'TianQiSpider'
	allowed_domains = ['www.weather.com.cn']
	start_urls = ['http://www.weather.com.cn/weather/101010100.shtml']
	def parse(self, response):
		subSelector = response.xpath('//*[@id="7d"]/ul/li')
		items = []
		for sub in subSelector:
			item = DemotianqiItem();
			item['shijian'] = sub.xpath('./h1/text()').extract()
			item['tianqi'] = sub.xpath('./p[1]/text()').extract()
			#item['qiWen'] = sub.xpath('./p[2]//text()')
			qiWen = '';
			for x in sub.xpath('./p[2]//text()').extract():
				if x != '\n':
					qiWen += x;
			item['qiWen'] = qiWen
			item['fengXiang1'] = sub.xpath('./p[3]/em/span[1]/@title').extract()
			item['fengXiang2'] = sub.xpath('./p[3]/em/span[2]/@title').extract()
			item['fengXiangJiBie'] = sub.xpath('./p[3]/i/text()').extract()
			items.append(item);
		return items
